﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBUtility;

public partial class Manageweb_ManageProduct_ProductRecycle : System.Web.UI.Page
{
    MODEL.Product MP = new MODEL.Product();
    MODEL.Product _MP = new MODEL.Product();

    BLL.Product BP = new BLL.Product();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["MasterID"] == null)
        {
            Response.Redirect("../Default.aspx");
        }
    }


    #region 产品图片 [格式化]
    protected string FormatThumb(object _Thumb)
    {
        if (_Thumb.ToString() == "")
        {
            return "~/Manageweb/images/null.jpg";
        }
        else
        {
            return "~/UploadImage/" + _Thumb.ToString();
        }
    }
    #endregion


    #region 修改按钮 [GridView] [Command]
    protected void LBtn_Mod_Command(object sender, CommandEventArgs e)
    {
        try
        {
            try
            {
                Response.Redirect("AddProduct.aspx?ProductID=" + e.CommandArgument.ToString());
            }
            catch (Exception ex)
            {
                LB_ProductRecycle.Text = ex.Message;
            }
        }
        catch (Exception ex)
        {
            LB_ProductRecycle.Text = ex.Message;
        }
    }
    #endregion


    #region 恢复按钮 [GridView] [Command]
    protected void LBtn_RollBack_Command(object sender, CommandEventArgs e)
    {
        try
        {
            MP.Product_ID = Convert.ToInt32(e.CommandArgument);

            BP.MarkIsDel(MP);

            GV_DelProductList.DataBind();

            LB_ProductRecycle.Text = "恢复成功";
        }
        catch (Exception ex)
        {
            LB_ProductRecycle.Text = ex.Message;
        }
    }
    #endregion


    #region 确认删除按钮 [GridView] [Command]
    protected void LBtn_RealDel_Command(object sender, CommandEventArgs e)
    {
        try
        {
            MP.Product_ID = Convert.ToInt32(e.CommandArgument);

            BP.Del(MP);

            LB_ProductRecycle.Text = "删除成功";

            GV_DelProductList.DataBind();
        }
        catch (Exception ex)
        {
            LB_ProductRecycle.Text = ex.Message;
        }
    }
    #endregion


    #region 搜索按钮 [Click]
    protected void Btn_Search_Click(object sender, EventArgs e)
    {
        try
        {
            string SQLstr_Search = "SELECT * FROM ([Product] INNER JOIN [ProductClass] ON Product.Product_ClassID = ProductClass.PC_ID) ";
            
            SQLstr_Search += " WHERE [Product_IsDel]=true AND [Product_Title] LIKE '%" + TB_Search.Text + "%' ";

            SQLstr_Search += " ORDER BY [Product_DateTime] DESC";

            DataTable DT_Search = AccHelper.GetDataTable(SQLstr_Search);

            GV_DelProductList.DataSourceID = "";

            GV_DelProductList.DataSource = DT_Search.DefaultView;

            GV_DelProductList.DataBind();
        }
        catch (Exception ex)
        {
            LB_ProductRecycle.Text = ex.Message;
        }
    }
    #endregion
}
